
//
//  MyCocos2DClass.m
//  ShootBall
//
//  Created by papo on 2/16/14.
//  Copyright 2014 __MyCompanyName__. All rights reserved.
//

#import "Banana.h"


@implementation Banana

+ (Banana*)bananaInWorld:(b2World*)world at:(CGPoint)pos {
    return [[self alloc] initWithFile:@"banana.png" inWorld:world at:pos];
}

- (id)initWithFile:(NSString *)filename inWorld:(b2World*)world at:(CGPoint)pos {
    self = [super initWithFile:filename];
    if (self) {
        [self createBumpInWorld:world at:pos];
    }
    return self;
}

- (void)createBumpInWorld:(b2World*)world at:(CGPoint)pos {
    [self setPosition:pos];
    
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position = [Helper toMeters:pos];
    bodyDef.angle = M_PI_2;
    bodyDef.userData = self;
    
    bodyDef.angularDamping = 2.8f;
    bodyDef.linearDamping = 4.8f;
    
    
    b2PolygonShape shape;
    shape.SetAsBox([self contentSize].width / PTM_RATIO / 2, [self contentSize].height / PTM_RATIO / 2);
    
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &shape;
    fixtureDef.density = 1.5f;
    fixtureDef.friction = 1.0f;
    fixtureDef.restitution = 1.0;
    
    body = world->CreateBody(&bodyDef);
    body->CreateFixture(&fixtureDef);
}

@end
